class Airport < ActiveRecord::Base
  
  #has_many :from_zjlys, :class_name => 'Zjlyprice', :foreign_key => 'from_id'
  #has_many :mid_zjlys, :class_name => 'Zjlyprice', :foreign_key => 'mid_id'
  #has_many :to_zjlys, :class_name => 'Zjlyprice', :foreign_key => 'to_id'
  
  has_many :from_orders, :class_name => 'WebOrder', :foreign_key => 'from_id'
  has_many :mid_orders, :class_name => 'WebOrder', :foreign_key => 'mid_id'
  has_many :to_orders, :class_name => 'WebOrder', :foreign_key => 'to_id'
  
  has_many :web_price_releases, :class_name => 'WebPriceRelease', :foreign_key => 'airport_from_id'
  has_many :policies, :class_name => 'Policy', :foreign_key => 'airport_from_id'
  def self.find_by_code(code)
    return Airport.find(:first,:conditions=>["airport_code=?",code])
  end
  
  def self.findHash
    hash = Hash.new
    as = Airport.find(:all)
    for a in as
      hash[a.airport_code] = a
    end
    return hash
  end
  
  def self.findByIDHash
    hash = Hash.new
    as = Airport.find(:all)
    for a in as
      hash[a.id] = a
    end
    return hash
  end
end
